<?php
class diadiemlanAdmin extends CI_Controller
{
	function danhsachddl()
	{
		$data = array( 
			'ddl'=>$this->mdiadiemlan->danhsachdiadiemlan(),
			'page'=>'danhsachdiadiemlan'
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xoaddlan($maddl)
	{
		$this->mdiadiemlan->xoaddl($maddl);
		redirect('admin/diadiemlanadmin/danhsachddl');	
	}
	
	function thongtinddl($maddl)
	{
		$data = array(
			'page'=>'thongtindiadiemlan',
			'ttddl'=>$this->mdiadiemlan->thongtindiadiemlan($maddl)
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xulycapnhat()
	{
		$maddl = $this->input->post('maddl');
		$tenddl = $this->input->post('tenddl');
		$mota = $this->input->post('mota');
		$hienthi = $this->input->post('hienthi')=='true' ? 'true' : 'false';
		
		//cap nhat hinh anh
		$config['upload_path'] = './asset/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1024';
		$config['encrypt_name']	= true;
		$this->load->library('upload', $config);
		$hinh = '';
		if($this->upload->do_upload('hinh'))
		{
			$df = array('upload_data' => $this->upload->data());
			$hinh = $df['upload_data']['file_name'];
		}
		if ($hinh == '')
			$hinh = $this->input->post('oldhinh');
			
		$this->mdiadiemlan->capnhatddl($maddl, $tenddl, $hinh, $mota, $hienthi);
		redirect('admin/diadiemlanadmin/danhsachddl');
	}
	
	function capnhatddlan($maddl)
	{
		$data = array('cnddl'=>$this->mdiadiemlan->thongtindiadiemlan($maddl),'page'=>'capnhatdiadiemlan');
		$this->load->view('admin/templateadmin',$data);
	}
	
	function themdiadiemlan()
	{
		$data = array(
			'page'=>'themdiadiemlan'
			
		);
		$this->load->view('admin/templateadmin', $data);
	}
	
	function xulythem()
	{
		$tenddl = $this->input->post('tenddl');	
		$mota = $this->input->post('mota');
		
		// Thuc hien upload hinh anh
		$config['upload_path'] = './asset/upload/';
		$config['allowed_types'] = 'gif|jpg|png';
		$config['max_size']	= '1024';
		$config['encrypt_name']	= true;
		$this->load->library('upload', $config);
		$hinh = '';
		if($this->upload->do_upload('hinh'))
		{
			$df = array('upload_data' => $this->upload->data());
			$hinh = $df['upload_data']['file_name'];
		}
		
		$hienthi = $this->input->post('hienthi')=='true' ? 'true' : 'false';
		$this->mdiadiemlan->themddl($tenddl, $hinh, $mota, $hienthi);
		redirect('admin/diadiemlanAdmin/danhsachddl');		
	}
}

?>